package com.angeho.vo;

import cn.hutool.json.JSONUtil;

import java.util.HashMap;

public class R extends HashMap<String, Object> {

    public static R ok() {
        R r = new R();
        r.put("code", 0);
        r.put("msg", "success");
        return r;
    }

    public static R ok(String msg) {
        R r = new R();
        r.put("code", 0);
        r.put("msg", msg);
        return r;
    }
    public static R fail(String msg) {
        R r = new R();
        r.put("code", 1);
        r.put("msg", msg);
        return r;
    }
    public R put(String key, Object value) {
        super.put(key, value);
        return this;
    }
    public R setMsg(String msg) {
        super.put("msg", msg);
        return this;
    }
    public R setCode(Integer code) {
        super.put("code", code);
        return this;
    }
    public R setData(Object data) {
        super.put("data", data);
        return this;
    }
    public R setTotal(Integer total) {
        super.put("total", total);
        return this;
    }
    public R setPage(Integer page) {
        super.put("page", page);
        return this;
    }
    public R setSize(Integer size) {
        super.put("size", size);
        return this;
    }
    public R setRows(Object rows) {
        super.put("rows", rows);
        return this;
    }
    public Integer getCode() {
        return (Integer) super.get("code");
    }
    public String getMsg() {
        return (String) super.get("msg");
    }

    @Override
    public String toString() {
        return JSONUtil.toJsonStr(this);
    }
}
